// run: time $exec < input
#include <iostream>
#include <string>
#include <cctype>

int const mo = 1000000007;
int const maxn = 200;
long long f[maxn][maxn][2];
int opt[maxn];  // 0 *       1 .        2 ^       3 !
bool num[maxn]; // 0 vector  1 number
int n;
std::string s;

bool get_num(int & p)
{
	bool ret = std::isdigit(s[p]);
	while (std::isdigit(s[p]) || std::isalpha(s[p])) p++;
	return ret;
}

int get_opt(int & p)
{
	char ch = s[p++];
	if (ch == '*') return 0;
	if (ch == '.') return 1;
	if (ch == '^') return 2;
	return 3;
}

void init()
{
	int p = 0;
	n = 0;
	num[n] = get_num(p);
	for (; p < (int)s.size(); ) {
		opt[n] = get_opt(p);
		num[++n] = get_num(p);
	}
	std::cerr << "----------\n";
	std::cout << num[i]
	for (int i = 0; i < n; i++)
}

int is_num(int op, bool l, bool r)
{
	if (!op) return (l && r);
	else if (op == 1) {
		if (!l && !r) return 1;
		return 2;
	} else if (op == 2) {
		if (!l && !r) return 1;
		return 2;
	} else return (!l && !r);
}

long long dp(int l, int r)
{
	if (f[l][r][0] != -1 && f[l][r][1] != -1)
		return f[l][r][0] + f[l][r][1];

	if (l == r) {
		f[l][r][num[l]] = 1;
		f[l][r][!num[l]] = 0;
		return 1;
	}

	for (int op = l; op < r; op++) {
		dp(l, op);
		dp(op + 1, r);

		for (int i = 0; i <= 1; i++) {
			long long t1 = f[l][op][i];
			for (int j = 0; j <= 1; j++) {
				long long t2 = f[op + 1][r][j];
				long long t3 = (t1 * t2) % mo;
				int tmp = is_num(opt[op], i, j);
				f[l][r][tmp] = std::max(f[l][r][tmp], t3);
			}
		}
	}

	if (f[l][r][0] == -1) f[l][r][0] = 0;
	if (f[l][r][1] == -1) f[l][r][1] = 0;
	return f[l][r][0] + f[l][r][1];
}

int main()
{
	std::ios::sync_with_stdio(false);
	int T;
	std::cin >> T;
	while (T--) {
		std::cin >> s;
		n = 0;
		init();

		std::cerr << "s = " << s << '\n';
		std::cerr << "n = " << n << '\n';

		for (int i = 0; i <= n; i++)
			for (int j = i; j <= n; j++) f[i][j][0] = f[i][j][1] = -1;
		std::cout << dp(0, n) << '\n';
	}
}

